﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FloatFall
{
    public class Snow
    {
        Random _rnd = new Random(DateTime.Now.Millisecond);

        public Image Image { get; set; }
        public Point CurPos { get; private set; }
        public Rectangle Area { get; private set; }
        public Point Direction { get; private set; }


        public Snow()
        {
            Area = new Rectangle(-100, -100, Screen.PrimaryScreen.WorkingArea.Width + 100, Screen.PrimaryScreen.WorkingArea.Height + 100);
            Init();
        }

        /// <summary>
        /// 飘落
        /// </summary>
        public void Float()
        {
            CurPos = new Point(CurPos.X + Direction.X, CurPos.Y + Direction.Y);
            if (!IsInArea())
                Init();

            //Debug.WriteLine($"CurPos:({CurPos.X},{CurPos.Y})");
        }

        /// <summary>
        /// 改变形状
        /// </summary>
        public void ChagneStyle()
        {
            if (_rnd.Next(1 % 10) % 4 == 0)
                Image.RotateFlip(RotateFlipType.Rotate270FlipNone);
        }

        /// <summary>
        /// 初始化
        /// </summary>
        private void Init()
        {
            CurPos = new Point(_rnd.Next(Area.Left, Area.Right), _rnd.Next(Area.Top, -10));
            Direction = new Point(_rnd.Next(2, 4) * (_rnd.Next(1, 10) % 2 == 0 ? 1 : -1), _rnd.Next(2, 5));
            Debug.WriteLine($"Direction:({Direction.X},{Direction.Y})");
        }

        /// <summary>
        /// 是否在区域内
        /// </summary>
        /// <returns></returns>
        private bool IsInArea()
        {
            return Area.Contains(CurPos);
        }

    }
}
